package com.geese.module.admin.controller;

import com.geese.common.BaseController;
import com.geese.common.vo.Page;
import com.geese.exception.BusinessException;
import com.geese.module.admin.service.ITransferService;
import com.geese.module.business.vo.TransferRecordVO;
import com.geese.module.user.model.SecurityUser;
import com.geese.module.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by huweiwei on 2017/3/27.
 */
@RestController
@RequestMapping("/admin/transfer")
public class TransferController extends BaseController{

    @Autowired
    private ITransferService transferService;
    @Autowired
    private UserService userService;

    /**
     * 商家财务打款信息列表
     * @param token
     * @param transferVO
     * @return
     */
    @GetMapping("/list")
    public String list(@RequestParam String token, TransferRecordVO transferVO) {
        Page page = getPageInfo(transferVO);
        Map<String, Object> result = transferService.selectList(page, transferVO);
        return response(result);
    }

    /**
     * 确认打款
     * @param token
     * @param id
     * @return
     */
    @PostMapping("/confirm")
    public String confirm(@RequestParam String token, @RequestParam int id, HttpServletRequest request) {
        SecurityUser user = userService.getLoginUser(token);
        if (id <= 0) {
            throw new BusinessException(120009);
        }
        Integer number = transferService.doConfirm(id);
        doLog(request, user, "确认打款，单号为：" + number);
        return response();
    }

    /**
     * 提醒打款
     * @param token
     * @param id
     * @return
     */
    @PostMapping("/remind")
    public String remind(@RequestParam String token, @RequestParam int id, HttpServletRequest request) {
        SecurityUser user = userService.getLoginUser(token);
        if (id <= 0) {
            throw new BusinessException(120009);
        }
        Integer number = transferService.doRemind(id);
        doLog(request, user, "提醒打款，单号为：" + number);
        return response();
    }
}
